//
//  HLComposePictureCell.m
//  weibo-OC
//
//  Created by 黄力 on 15/12/26.
//  Copyright © 2015年 HLTest. All rights reserved.
//

#import "HLComposePictureCell.h"
#import <Masonry.h>

@interface HLComposePictureCell ()
//添加按钮
@property (nonatomic,strong) UIButton *composePictureAddBtn;
//删除按钮
@property (nonatomic,strong) UIButton *composePictureDeleteBtn;
@end

@implementation HLComposePictureCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    //设置界面
    [self setupUI];
    return self;
}

//设置界面
- (void)setupUI {
    //添加子控件
    [self.contentView addSubview:self.composePictureAddBtn];
    [self.contentView addSubview:self.composePictureDeleteBtn];
    //设置约束
    //添加按钮
    [self.composePictureAddBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    //删除按钮
    [self.composePictureDeleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.equalTo(self.composePictureAddBtn);
    }];
    //添加点击响应事件
    [self.composePictureAddBtn addTarget:self action:@selector(clcikComposePictureAddBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.composePictureDeleteBtn addTarget:self action:@selector(clickComposePictureDeleteBtn) forControlEvents:UIControlEventTouchUpInside];
}

//点击添加按钮
- (void)clcikComposePictureAddBtn {
    //判断代理方法是否有响应
    if ([self.delegate respondsToSelector:@selector(composePictureCellDidClickAddBtn:)]) {
        [self.delegate composePictureCellDidClickAddBtn:self];
    }
}

//点击删除按钮
- (void)clickComposePictureDeleteBtn {
    //判断代理方法是否有响应
    if ([self.delegate respondsToSelector:@selector(composePictureCellDidClickDeleteBtn:)]) {
        [self.delegate composePictureCellDidClickDeleteBtn:self];
    }
}

//重写setter方法
- (void)setComposeImage:(UIImage *)composeImage {
    _composeImage = composeImage;
    //给按钮设置图片
    [self.composePictureAddBtn setImage:composeImage forState:UIControlStateNormal];
    //如果时最后一张就隐藏删除按钮
    if (composeImage == nil) {
        self.composePictureAddBtn.userInteractionEnabled = YES;
        self.composePictureDeleteBtn.hidden = YES;
    }else {
        self.composePictureAddBtn.userInteractionEnabled = NO;
        self.composePictureDeleteBtn.hidden = NO;
    }
}

#pragma mark - 懒加载
//添加按钮
- (UIButton *)composePictureAddBtn {
    if (_composePictureAddBtn == nil) {
        _composePictureAddBtn = [[UIButton alloc] initWithImageName:nil withBackImageName:@"compose_pic_add"];
        //设置按钮内容的显示模式
        _composePictureAddBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _composePictureAddBtn;
}
//删除按钮
- (UIButton *)composePictureDeleteBtn {
    if (_composePictureDeleteBtn == nil) {
        _composePictureDeleteBtn = [[UIButton alloc] initWithImageName:nil withBackImageName:@"compose_photo_close"];
    }
    return _composePictureDeleteBtn;
}

@end
